﻿@model QuanLyGiaoVuUI.Models.LopMonHoc.CapNhatLopMonHocViewModel

@{
    Layout = "~/Views/Shared/_blueWhaleLayout.cshtml";
}

@using QuanLyGiaoVuService.Utilities;

<style>
    .hiddenField {
        display: none;
    }
</style>

<div id="sidebar">
    @{Html.RenderPartial("LopMonHocMenuPartial");}
</div>

<div id="main" class="grid_10">
    <!--  start page-heading -->

    <div id="page-heading" class="box round first grid">
        @if (Model.LopMonHocId == null || Model.LopMonHocId.Equals(Guid.Empty))
        {
            <h2>Thêm lớp môn học</h2>
        }
        else
        {
            <h2>Sửa thông tin lớp môn học</h2>
        }
        <div class="block">
            <input type="hidden" value="" id="thutugiangvien" />
            @{Html.EnableClientValidation();}
            @using (Html.BeginForm("CapNhat", "LopMonHoc"))
            {
                @Html.ValidationSummary(true)
    
                <fieldset>
                    <table class="form">
                        <tr>
                            @Html.HiddenFor(model => model.LopMonHocId)
                            @Html.HiddenFor(model => model.ChiLopThucHanh)
                        </tr>
                        <tr>
                            <th class="formLabel">
                                <div class="editor-label">
                                    @Html.LabelFor(model => model.MaLopMonHoc)
                                </div>
                            </th>
                            <td>
                                <div class="editor-field">
                                    <span id="maLopDau">@Model.PhanDauMaLop</span>
                                    @if (Model.GiangVienXacNhan)
                                    { 
                                        @Html.HiddenFor(model => model.MaLopMonHoc)
                                        <strong>@Model.MaLopMonHoc</strong>
                                    }
                                    else
                                    {
                                    @Html.EditorFor(model => model.MaLopMonHoc)
                                    @Html.ValidationMessageFor(model => model.MaLopMonHoc)
                                    }
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <th class="formLabel">
                                <div class="editor-label">
                                    @Html.LabelFor(model => model.MaMonHoc)
                                </div>
                            </th>
                            <td>
                                @if(!Model.GiangVienXacNhan)
                                {
                                <div class="editor-field">
                                    @if (Model.MonHoc == null || Model.MaMonHoc.Equals(Guid.Empty))
                                    {
                                        <a id="TenMonHoc" href="javascript:;">Chọn</a>
                                        <input type="hidden" value="" id="MaMonHoc" name="MaMonHoc" />
                                    }
                                    else
                                    {
                                        <a id="TenMonHoc" href="#">@Model.MonHoc.MaVaTenMonHoc</a>
                                        <input type="hidden" value="@Model.MaMonHoc" id="MaMonHoc" name="MaMonHoc" />
                                    }
                                    @Html.ValidationMessageFor(model => model.MaMonHoc)
                                </div>
                                }
                                else
                                {
                                    <div class="editor-field">
                                        @Html.HiddenFor(model => model.MaMonHoc)
                                        <strong>@Model.MonHoc.MaVaTenMonHoc</strong>
                                    </div>
                                }
                            </td>
                        </tr>
                        <tr>
                            <th class="formLabel">
                                <div class="editor-label">
                                    @Html.LabelFor(model => model.LopSinhVienId)
                                </div>
                            </th>
                            <td>
                                <div class="editor-field">
                                    @if(!Model.GiangVienXacNhan)
                                    {
                                    @Html.DropDownList("LopSinhVienId", new SelectList(Model.DanhSachLopSinhVien, "MaLop", "TenLop", Model.DanhSachLopSinhVien.ToList().Find(obj => obj.MaLop == Model.LopSinhVienId)))
                                    @Html.ValidationMessageFor(model => model.LopSinhVienId)
                                    }
                                    else
                                    {
                                    @Html.DropDownList("LopSinhVienId", new SelectList(Model.DanhSachLopSinhVien, "MaLop", "TenLop", Model.DanhSachLopSinhVien.ToList().Find(obj => obj.MaLop == Model.LopSinhVienId)), new { @disabled = "disabled" })
                                    }
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <th class="formLabel">
                                <div class="editor-label">
                                    @Html.LabelFor(model => model.MaGiangVien1)
                                </div>
                            </th>
                            <td>
                                <div class="editor-field">
                                    @if (Model.MaGiangVien1 == null || Model.MaGiangVien1.Equals(Guid.Empty))
                                    {
                                        <a id="TenGiangVien1" href="#">Chọn</a>
                                        <input type="hidden" value="" id="MaGiangVien1" name="MaGiangVien1" />
                                    }
                                    else
                                    {
                                        <a id="TenGiangVien1" href="#">@Model.GiangVien1.GetTenVaHocVi()</a>
                                        <input type="hidden" value="@Model.MaGiangVien1" id="MaGiangVien1" name="MaGiangVien1" />
                                    }
                                    @Html.ValidationMessageFor(model => model.MaGiangVien1)
                                </div>
                            </td>
                        </tr>
                        <tr id="GiangVien2Holder" class="@((Model.LoaiLop == ThamSoConstantUtility.LOAILOPTHUCHANH1 || Model.LoaiLop == ThamSoConstantUtility.LOAILOPTHUCHANH2) ? "" : "hiddenField")">
                            <th class="formLabel">
                                <div class="editor-label">
                                    @Html.LabelFor(model => model.MaGiangVien2)
                                </div>
                            </th>
                            <td>
                                <div class="editor-field">
                                    @if (Model.MaGiangVien2 == null || Model.MaGiangVien2.Equals(Guid.Empty))
                                    {
                                        <a id="TenGiangVien2" href="#">Chọn</a>
                                        <input type="hidden" value="" id="MaGiangVien2" name="MaGiangVien2" />
                                    }
                                    else
                                    {
                                        <a id="TenGiangVien2" href="#">@Model.GiangVien2.GetTenVaHocVi()</a>
                                        <input type="hidden" value="@Model.MaGiangVien2" id="MaGiangVien2" name="MaGiangVien2" />
                                    }
                                    @Html.ValidationMessageFor(model => model.MaGiangVien2)
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <th class="formLabel">
                                <div class="editor-label">
                                    @Html.LabelFor(model => model.MaHocKy)
                                </div>
                            </th>
                            <td>
                                <div class="editor-field">
                                    @Html.DropDownListFor(model => model.MaHocKy, new SelectList(Model.DanhSachHocKy, "MaHocKy", "TenHocKyDayDu"))
                                    @Html.ValidationMessageFor(model => model.MaHocKy)
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <th class="formLabel">
                                <div class="editor-label">
                                    @Html.LabelFor(model => model.SiSoToiDa)
                                </div>
                            </th>
                            <td>
                                <div class="editor-field">
                                    @Html.EditorFor(model => model.SiSoToiDa)
                                    @Html.ValidationMessageFor(model => model.SiSoToiDa)
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <th class="formLabel">
                                <div class="editor-label">
                                    @Html.LabelFor(model => model.SiSoThucTe)
                                </div>
                            </th>
                            <td>
                                <div class="editor-field">
                                    @Html.EditorFor(model => model.SiSoThucTe)
                                    @Html.ValidationMessageFor(model => model.SiSoThucTe)
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <th class="formLabel">
                                <div class="editor-label">
                                    @Html.LabelFor(model => model.Phong)
                                </div>
                            </th>
                            <td>
                                <div class="editor-field">
                                    @Html.EditorFor(model => model.Phong)
                                    @Html.ValidationMessageFor(model => model.Phong)
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <th class="formLabel">
                                <div class="editor-label">
                                    @Html.LabelFor(model => model.LoaiLop)
                                </div>
                            </th>
                            <td>
                                <div class="editor-field">
                                    @if (!(Model.LopMonHocId == null || Model.LopMonHocId.Equals(Guid.Empty)))
                                    {
                                        <span style="font-weight: bold">@(Model.LoaiLop == 0 ? "Lý Thuyết" : (Model.LoaiLop == 1 ? "Thực Hành (Hình thức 1)" : "Thực Hành (Hình thức 2)"))</span>
                                        <input name="LoaiLop" value="@Model.LoaiLop" type="hidden" />
                                    }
                                    else
                                    {
                                        <select name="LoaiLop" id="LoaiLop">
                                            @if (!Model.ChiLopThucHanh)
                                            {
                                                <option value="0">Lý Thuyết</option>
                                            }
                                            <option value="1">Thực Hành (Hình thức 1)</option>
                                            <option value="2">Thực Hành (Hình thức 2)</option>
                                        </select>
                                    }
                                    @Html.ValidationMessageFor(model => model.LoaiLop)
                                </div>
                            </td>
                        </tr>
                        @if (Model.LoaiLop == ThamSoConstantUtility.LOAILOPLYTHUYET && Model.MonHoc != null && (Model.MonHoc.SoTinChiLyThuyet < Model.MonHoc.TongSoTinChi))
                        {
                            <tr id="DanhSachLopThucHanh" class="@(Model.LoaiLop == 0 ? "" : "hiddenField")">
                                <td colspan="2">
                                    <div class="editor-label">
                                        <label>Danh sách lớp thực hành</label>
                                        <a href="/LopMonHoc/TaoLopThucHanh?maLopLyThuyet=@Model.LopMonHocId" id="btnThemLopThucHanh">Thêm lớp</a>
                                    </div>
                                    <div>
                                        <table class="data display datatable">
                                            <thead>
                                                <tr>
                                                    <th class="sorting">Mã lớp - Tên môn học
                                                    </th>
                                                    <th class="sorting">Giảng viên 1
                                                    </th>
                                                    <th class="sorting">Giảng viên 2
                                                    </th>
                                                    <th class="sorting">Thứ
                                                    </th>
                                                    <th class="sorting">Tiết
                                                    </th>
                                                    <th class="sorting">Xem chi tiết
                                                    </th>

                                                </tr>
                                            </thead>
                                            @{int count = 0;}
                                            @foreach (var lopTH in Model.DanhSachLopThucHanh)
                                            { 
                                                <tr class="gradeA @(++count % 2 == 0 ? "even" : "odd")">
                                                    <td>
                                                        @lopTH.MaLopVaTenMonHoc
                                                    </td>
                                                    <td>
                                                        @lopTH.GiangVien1.GetTenVaHocVi()
                                                    </td>
                                                    <td>
                                                        @(lopTH.GiangVien2 != null ? lopTH.GiangVien2.GetTenVaHocVi() : string.Empty)
                                                    </td>
                                                    <td>
                                                        @(lopTH.Thu <= 1 ? "-" : lopTH.Thu.ToString())
                                                    </td>
                                                    <td>
                                                        @(lopTH.Thu <= 1 ? "-" : @lopTH.TietDayString)
                                                    </td>
                                                    <td>
                                                        @Html.ActionLink("Xem chi tiết", "CapNhat", new { id = lopTH.LopMonHocId })
                                                    </td>
                                                </tr>
                                            }
                                        </table>
                                    </div>
                                </td>
                            </tr>
                        }
                        <tr id="ChonLopLyThuyetHolder" class="@(Model.LoaiLop != ThamSoConstantUtility.LOAILOPLYTHUYET ? "" : "hiddenField")">
                            <th class="formLabel">
                                <div class="editor-label">
                                    @Html.LabelFor(model => model.MaLopChinh)
                                </div>
                            </th>
                            <td>
                                <div class="editor-field">
                                    @if (Model.MaLopChinh == null || Model.MaLopChinh.Equals(Guid.Empty))
                                    {
                                        <a id="TenLopChinh" href="#">Chọn</a>
                                        <input type="hidden" value="" id="MaLopChinh" name="MaLopChinh" />
                                    }
                                    else
                                    {
                                        <a id="TenLopChinh" href="#">@Model.LopChinh.MaLopVaTenMonHoc</a>
                                        <input type="hidden" value="@Model.MaLopChinh" id="MaLopChinh" name="MaLopChinh" />
                                    }
                                    @Html.ValidationMessageFor(model => model.MaLopChinh)
                                </div>
                            </td>
                        </tr>
                    </table>
                    @if (!(Model.LopMonHocId == null || Model.LopMonHocId.Equals(Guid.Empty)))// && (Model.LoaiLopMonHoc != null && Model.LoaiLopMonHoc.TenLoaiLopMonHoc.Contains("Thực Hành")))
                    { 
                        <table class="form">
                            <tr>
                                <th class="formLabel">
                                    <div class="editor-label">
                                        @Html.CheckBoxFor(m => m.CapNhatLichDay)
                                        @Html.LabelFor(m => m.CapNhatLichDay)
                                    </div>
                                </th>
                                <td>
                                    <div class="editor-field">
                                    </div>
                                </td>
                            </tr>
                            </table>
                        <table class="form">
                            <tr class="lichGiangDay">
                                <th class="formLabel">
                                    <div class="editor-label">
                                        @Html.LabelFor(model => model.Thu)
                                    </div>
                                </th>
                                <td>
                                    <select name="Thu" id="Thu">
                                        <option id="Thu2" value="2">Thứ Hai</option>
                                        <option id="Thu3" value="3">Thứ Ba</option>
                                        <option id="Thu4" value="4">Thứ Tư</option>
                                        <option id="Thu5" value="5">Thứ Năm</option>
                                        <option id="Thu6" value="6">Thứ Sáu</option>
                                        <option id="Thu7" value="7">Thứ Bảy</option>
                                    </select>
                                </td>
                            </tr>
                            <tr class="lichGiangDay">
                                <th class="formLabel">
                                    <div class="editor-label">
                                        @Html.LabelFor(model => model.MaTietDau)
                                    </div>
                                </th>
                                <td>
                                    @Html.DropDownListFor(model => model.MaTietDau, new SelectList(Model.DanhSachTiet, "MaTiet", "TietThu"))
                                    @Html.ValidationMessageFor(model => model.MaTietDau)
                                </td>
                                <td>
                                        <div class="lichGiangDay">
                                            <a href="javascript:;" id="btnChonLichDay">Mở bảng thời gian</a>
                                        </div>
                                </td>
                            </tr>
                            <tr class="lichGiangDay">
                                <th class="formLabel">
                                    <div class="editor-label">
                                        @Html.LabelFor(model => model.MaTietSau)
                                    </div>
                                </th>
                                <td>
                                    @Html.DropDownListFor(model => model.MaTietSau, new SelectList(Model.DanhSachTiet, "MaTiet", "TietThu"))
                                </td>
                            </tr>
                        </table>
                        if (Model.LoaiLop == ThamSoConstantUtility.LOAILOPTHUCHANH2)
                        {
                        <table class="form">
                            <tr class="lichGiangDay">
                                <th class="formLabel">
                                    <div class="editor-label">
                                        @Html.LabelFor(model => model.Buoi1)
                                    </div>
                                </th>
                                <td>
                                    <select name="SC1" id="SC1">
                                        <option value="0">Sáng</option>
                                        <option value="1">Chiều</option>
                                    </select>
                                    <label>Ngày: </label>@Html.TextBox("Buoi1", Model.Buoi1.HasValue ? Model.Buoi1.Value.ToShortDateString() : String.Empty, new { @class = "date_picker" })
                                </td>
                            </tr>
                            <tr class="lichGiangDay">
                                <th class="formLabel">
                                    <div class="editor-label">
                                        @Html.LabelFor(model => model.Buoi2)
                                    </div>
                                </th>
                                <td>
                                    <select name="SC2" id="SC2">
                                        <option value="0">Sáng</option>
                                        <option value="1">Chiều</option>
                                    </select>
                                    <label>Ngày: </label>@Html.TextBox("Buoi2", Model.Buoi2.HasValue ? Model.Buoi2.Value.ToShortDateString() : String.Empty, new { @class = "date_picker" })
                                </td>
                            </tr>
                            <tr class="lichGiangDay">
                                <th class="formLabel">
                                    <div class="editor-label">
                                        @Html.LabelFor(model => model.Buoi3)
                                    </div>
                                </th>
                                <td>
                                    <select name="SC3" id="SC3">
                                        <option value="0">Sáng</option>
                                        <option value="1">Chiều</option>
                                    </select>
                                    <label>Ngày: </label>@Html.TextBox("Buoi3", Model.Buoi3.HasValue ? Model.Buoi3.Value.ToShortDateString() : String.Empty, new { @class = "date_picker" })
                                </td>
                            </tr>
                        </table>
                        }
                    }
                    <p>
                        <input id="lopmonhoc-submit" type="submit" value="Lưu" />
                    </p>
                </fieldset>
                                        
            }
        </div>
    </div>


    <div id="dsMonHocDialog"></div>
    <div id="dsGiangVienDialog"></div>
    <div id="dsLopMonHocDialog"></div>
    <div id="dsLopLyThuyetDialog"></div>
    <div id="bangGioDay"></div>
    <script>
        var xacNhan = "@(Model.GiangVienXacNhan)".toLowerCase() == "true";

        function ShowMonHocListDialog() {
            if (xacNhan)
                return false;
            var maLop = $("#LopSinhVienId").val();
            LayDanhSachMonHoc(maLop);
        }

        function ShowGiangVienListDialog(thutu) {
            if (xacNhan)
                return false;
            var monHocIdParam = "monHocId=" + $("#MaMonHoc").val();
            var thuTuGVKhac = 3 - thutu;
            var giangVienIdParam = "giangVienId=" + $("#MaGiangVien" + thuTuGVKhac).val();
            var param = "?" + monHocIdParam + "&" + giangVienIdParam;
            $("#dsGiangVienDialog").load("/LopMonHoc/LayDanhSachGiangVien" + param);
            $("#thutugiangvien").val(thutu);
            $("#dsGiangVienDialog").dialog("open");
        }

        function ShowLopLyThuyetListDialog() {
            var maLopMonHocParam = "maLopMonHoc=" + $("#LopMonHocId").val();
            var maMonHocParam = "maMonHoc=" + $("#MaMonHoc").val();
            var maHocKyParam = "maHocKy=" + $("#MaHocKy").val();
            var param = "?" + maLopMonHocParam + "&" + maMonHocParam + "&" + maHocKyParam;
            $("#dsLopLyThuyetDialog").load("/LopMonHoc/LayDanhSachLopLyThuyet" + param, function () {
                $("#dsLopLyThuyetDialog").dialog({
                    title: "Chọn lớp lý thuyết",
                    autoOpen: true,
                    width: 800,
                    height: 600,
                    buttons: {
                        "Chọn": function () {
                            if (LayDanhSachLopLyThuyetObject != null) {
                                if (LayDanhSachLopLyThuyetObject.SelectedId != null) {
                                    $("#MaLopChinh").val(LayDanhSachLopLyThuyetObject.SelectedId);
                                    $("#TenLopChinh").html(LayDanhSachLopLyThuyetObject.GetMaLopVaTenMonHoc());
                                    $("#dsLopLyThuyetDialog").dialog("close");
                                }
                            }
                        },
                        "Bỏ chọn": function () {
                            $("#MaLopChinh").val("");
                            $("#TenLopChinh").html("Chọn");
                            $("#dsLopLyThuyetDialog").dialog("close");
                        }
                    }
                });
            });
        }

        function ShowBangGioDay() {
            var maLopMonHocParam = "maLopMonHoc=" + $("#LopMonHocId").val();
            var maMonHocParam = "maMonHoc=" + $("#MaMonHoc").val();
            var maGiangVien1Param = "maGiangVien1=" + $("#MaGiangVien1").val();
            var maGiangVien2Param = "maGiangVien2=" + $("#MaGiangVien2").val();
            var maLopSinhVienParam = "maLopSinhVien=" + $("#LopSinhVienId").val();
            var maHocKyParam = "maHocKy=" + $("#MaHocKy").val();
            var param = "?" + maLopMonHocParam + "&" + maMonHocParam + "&" + maGiangVien1Param + "&" + maGiangVien2Param + "&" + maLopSinhVienParam + "&" + maHocKyParam;
            $("#bangGioDay").load("/LopMonHoc/ChonLichGiangDayDialog" + param, function () {
                $("#bangGioDay").dialog({
                    autoOpen: true,
                    modal: true,
                    title: "Chọn lịch giảng dạy",
                    width: 1088,
                    height: 400,
                    buttons: {
                        "Chọn": function () {
                            if (ChonLichGiangDayObject != null && ChonLichGiangDayObject.KhaNangDuocChon != null) {
                                TinhLichGiangDay(ChonLichGiangDayObject.KhaNangDuocChon, ChonLichGiangDayObject.SoTinChiLT,ChonLichGiangDayObject.LaLopThucHanh);
                                $("#bangGioDay").dialog("close");
                            }
                        }
                    }
                });
            });
        }

        function ShowLopMonHocListDialog() {
            if (xacNhan)
                return false;
            $("#dsLopMonHocDialog").dialog("open");
        }

        function LayDanhSachMonHoc(maLop) {
            $("#dsMonHocDialog").load("/LopMonHoc/LayDanhSachMonHoc?maLop=" + maLop);
            $("#dsMonHocDialog").dialog({
                title: "Chọn môn học",
                autoOpen: true, modal: true, width: 800, height: "auto", buttons: {
                    "Chọn": function () {
                        if ($("#selectedMonHocId").val() != null && $("#selectedMonHocId").val() != "") {
                            $("#MaMonHoc").val($("#selectedMonHocId").val());
                            $("#TenMonHoc").html($("#maVaTenMonHoc").val());
                            $("#maLopDau").html($("#maMonHoc").val() + ".");
                        }
                        $("#dsMonHocDialog").dialog("close");
                    }
                }
            });
        }

        function TinhLichGiangDay(KhaNangDuocChon, SoTinChiLT, LaLopThucHanh) {
            var Thu = Math.floor((KhaNangDuocChon - 1) / 4) + 2;
            var oddValue = (KhaNangDuocChon - 1) % 4;
            var TietDau, TietSau;
            switch (oddValue) {
                case 0: {
                    if (SoTinChiLT <= 2 || LaLopThucHanh) {
                        TietDau = 1;
                        TietSau = 3;
                    }
                    else {
                        TietDau = 1;
                        TietSau = 5;
                    }

                    break;
                }
                case 1: {
                    TietDau = 4;
                    TietSau = 5;
                    break;
                }
                case 2: {
                    if (SoTinChiLT <= 2 || LaLopThucHanh) {
                        TietDau = 6;
                        TietSau = 7;
                    }
                    else {
                        TietDau = 6;
                        TietSau = 9;
                    }
                    break;
                }
                case 3: {
                    TietDau = 8;
                    TietSau = 9;
                }
            }
            DatLichGiangDay(Thu, TietDau, TietSau);
        }

        function DatLichGiangDay(Thu, TietDau, TietSau) {
            $.ajax({
                type: "get",
                url: "/LopMonHoc/LayThongTinTietHoc",
                data: {
                    tietDau: TietDau,
                    tietSau: TietSau
                },
                success: function (data) {
                    if (data.success) {
                        DatGiaTriChoSelectBox("Thu", Thu);
                        DatGiaTriChoSelectBox("MaTietDau", data.TietDau.MaTiet);
                        DatGiaTriChoSelectBox("MaTietSau", data.TietSau.MaTiet);
                    }
                    else {
                        ToastManager.showStickyWarningToast("Có lỗi xảy ra. Hãy thử lại.");
                    }
                }
            });
        }

        function DatGiaTriChoSelectBox(objectId, dataId) {
            $("#" + objectId + " option").each(function () {
                $(this).removeProp('selected');
                if ($(this).val() == dataId) {
                    $(this).prop('selected', true);
                    return false;
                }
            });
        }

        $(document).ready(function () {
            var capNhatLichGiangDay = $("#CapNhatLichDay").is(":checked");
            if (!capNhatLichGiangDay)
                $(".lichGiangDay").addClass("hiddenField");
            $(".date_picker").datepicker();
            $("#SC1").val(@Model.SC1);
            $("#SC2").val(@Model.SC2);
            $("#SC3").val(@Model.SC3);

            $("#CapNhatLichDay").bind("change", function () {
                if ($(this).is(":checked")) {
                    $(".lichGiangDay").removeClass("hiddenField");
                }
                else {
                    $(".lichGiangDay").each(function () {
                        if (!$(this).hasClass("hiddenField")) {
                            $(this).addClass("hiddenField");
                        }
                    });
                }
            });
            $("#LoaiLop").bind("change", function () {
                var loaiLop = $("#LoaiLop").val();
                if (loaiLop != 0) {
                    $("#ChonLopLyThuyetHolder").removeClass("hiddenField");
                    $("#GiangVien2Holder").removeClass("hiddenField");
                    if (!$("#DanhSachLopThucHanh").hasClass("hiddenField"))
                        $("#DanhSachLopThucHanh").addClass("hiddenField");
                }
                else {
                    $("#DanhSachLopThucHanh").removeClass("hiddenField");

                    if (!$("#GiangVien2Holder").hasClass("hiddenField")) {
                        $("#GiangVien2Holder").addClass("hiddenField");
                    }
                    if (!$("#ChonLopLyThuyetHolder").hasClass("hiddenField"))
                        $("#ChonLopLyThuyetHolder").addClass("hiddenField");
                }
            });

            try {
                var thu = '@Model.Thu';
                    $("#thu option").each(function () {
                        $(this).removeAttr("selected");
                    });
                    $("#Thu" + thu).attr("selected", "selected");
                }
            catch (exception)
            { }

            $("#SiSoToiDa").spinner();

            $("#SiSoThucTe").spinner();

            $("#dsLopMonHocDialog").load("/LopMonHoc/LayDanhSachLopMonHoc");

            $("#dsGiangVienDialog").dialog({
                title: "Chọn giảng viên",
                autoOpen: false, modal: true, width: 800, height: "auto", buttons: {
                    "Chọn": function () {
                        var thutu = $("#thutugiangvien").val();
                        if ($("#selectedGiangVienId").val() != null && $("#selectedGiangVienId").val() != "") {
                            $("#MaGiangVien" + thutu).val($("#selectedGiangVienId").val());
                            $("#TenGiangVien" + thutu).html($("#thongtinGiangVien").val());
                        }
                        $("#dsGiangVienDialog").dialog("close");
                    },
                    "Bỏ chọn": function () {
                        var thutu = $("#thutugiangvien").val();
                        $("#MaGiangVien" + thutu).val("");
                        $("#TenGiangVien" + thutu).html("Chọn");
                        $("#dsGiangVienDialog").dialog("close");
                    }
                }
            });
            $("#dsLopMonHocDialog").dialog({ autoOpen: false, modal: true, width: 800, height: "auto" });
            $("#TenMonHoc").click(0, function () {
                ShowMonHocListDialog();
            });

            $("#TenGiangVien1").click(0, function () {
                ShowGiangVienListDialog(1);
            });

            $("#TenGiangVien2").click(0, function () {
                ShowGiangVienListDialog(2);
            });

            $("#TenLopChinh").click(0, function () {
                ShowLopLyThuyetListDialog();
            });

            $("#lopmonhoc-submit").button();

            $("#btnChonLichDay").button().bind("click", function () {
                ShowBangGioDay();
            });
            $("#btnChonLichDay").bind("mouseenter", function () {
                console.log("in");
                $(this).closest("table").css({
                    "background-color": "red"
                });
            });
            $("#btnChonLichDay").bind("mouseleave", function () {
                console.log("out");
                $(this).closest("table").css({
                    "background-color": "white"
                });
            });

            $("#btnThemLopThucHanh").button();

            var loaiLop = parseInt('@(Model.LoaiLop)');
            $("#LoaiLop").find("option").each(function () {
                var val = $(this).prop("value");
                if (val == loaiLop)
                    $(this).prop("selected", "selected");
            });
        });


    </script>
